<?php

namespace App\services;
use Qiniu\Auth;
use Qiniu\Storage\UploadManager;

class Qiniu
{
    public $accessKey = 'ja9K3G7K4gTc0Fa0OVt-XXJvkE2HuCfp2bTVf-R7';
    public $secretKey = 'ixpGS5EN3fhK3xK2QPTKA2wvB74w3lQwKpA3A0a9';
    public $bucket = 'wenhetong';

    public function upload($uri){
// 构建鉴权对象
        $auth = new Auth($this->accessKey, $this->secretKey);
// 生成上传 Token
        $token = $auth->uploadToken($this->bucket);
        $filePath =public_path($uri);
        $key = '';
        // 初始化 UploadManager 对象并进行文件的上传。
        $uploadMgr = new UploadManager();
        // 调用 UploadManager 的 putFile 方法进行文件的上传。
        list($ret, $err) = $uploadMgr->putFile($token, $key, $filePath, null, 'application/octet-stream', true, null, 'v2');
        echo "\n====> putFile result: \n";
        if ($err !== null) {
            var_dump($err);
        } else {
            var_dump($ret);
        }
    }
}
